﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class TimeCCL : MonoBehaviour {

	// Use this for initialization
    public float LongTime = 4f;
    public float nowTime = 4f;
    float velue = 0;
    public Image bar;
    private manCCL man;
    public int speed = 5;
    void Start() 
    {
       man= GameObject.FindGameObjectWithTag("Player").GetComponent<manCCL>();
    }
	
	// Update is called once per frame
	void Update () {

        if ( man.state==GameState.runing)
        {
            nowTime -= Time.deltaTime;
            velue = nowTime / LongTime;
            bar.fillAmount = velue;
            if (velue <= 0)
            {
                man.state = GameState.over;
                man.message.SetActive(true);
            }
        }
        if (man.state == GameState.runing)
        {
            if (Input.GetMouseButtonDown(0))
            {
                nowTime += Time.deltaTime * speed;
            }
        }
	}
}
